import React from 'react';
import { inject, observer } from 'mobx-react';
import {WeaTableNew} from 'comsMobx';
const WeaTable = WeaTableNew.WeaTable;
import * as mobx from 'mobx';
import {WeaErrorPage,WeaTools} from 'ecCom';
import {SubWorkflowStatusStore} from '../../stores';

import {Button,Modal,message} from 'antd';
import {WeaTop, WeaRightMenu, WeaTab, WeaPopoverHrm, WeaLocaleProvider} from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;
//自定义组件
import Condition from '../supervise/Condition';

 @inject('SubWorkflowStatusStore')

 @observer
class SubWorkflowStatus extends React.Component{

  constructor(props){
    super(props);
    this.doInit(this.props);
  }
  doInit(props){
    const { location,SubWorkflowStatusStore } = props;
    SubWorkflowStatusStore.init(location.query || {});
    _ListenerCtrl.bind();
  }
  componentDidMount() {

  }
  componentWillUnmount(){
    const { SubWorkflowStatusStore } = this.props;
    SubWorkflowStatusStore.clearStatus();
    _ListenerCtrl.bind();
  }
  
  componentWillReceiveProps(nextProps) {
    if(this.props.location.key !== nextProps.location.key) {
        const { SubWorkflowStatusStore } = this.props;
        SubWorkflowStatusStore.clearStatus();
        this.doInit(nextProps);
    }
  }

  render(){
    const {SubWorkflowStatusStore, location = {}} = this.props;
    const {loading,title,showSearchAd,form,tableStore,topTab, tabKey, smsVisible, smsParams,showBatchSubmit, emailVisible,fwquery} = SubWorkflowStatusStore;
    const formParams = form.getFormParams() || {};
    const loadingTable = tableStore.loading;

    return(
        <div style={{height:"100%",width:"100%"}} className='wf-pc4mobx-subWorkflowStatus'>
          <WeaPopoverHrm ecId={`${this && this.props && this.props.ecId || ''}_WeaPopoverHrm@wo0eir`} />
          <WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@m5st66`} datas={this.getRightMenu()} collectParams={{favname:title, favouritetype: '2' ,importantlevel:'1'}}>
              <WeaTop ecId={`${this && this.props && this.props.ecId || ''}_WeaTop@7lwc9c`}
                title={title}
                loading={loading || loadingTable}
                icon={<i className='icon-coms-workflow' />}
                iconBgcolor='#0079DE'
                buttonSpace={10}
                showDropIcon={true}
                dropMenuDatas={this.getRightMenu()}
              >
                 <WeaTab ecId={`${this && this.props && this.props.ecId || ''}_WeaTab@bjdk44`}
                    buttonsAd={this.getTabButtonsAd()}
                    searchType={['base','advanced']}
                    advanceHeight={160}
                    setShowSearchAd={bool=>{SubWorkflowStatusStore.setShowSearchAd(bool)}}
                    hideSearchAd={()=> SubWorkflowStatusStore.setShowSearchAd(false)}
                    showSearchAd={showSearchAd}
                    searchsBaseValue={formParams.requestname}
                    searchsAd={
                        <Condition ecId={`${this && this.props && this.props.ecId || ''}_Condition@rekud7`} queryStore={SubWorkflowStatusStore} />
                    }
                    onSearch={v=>{SubWorkflowStatusStore.getSessionkey()}}
                    onSearchChange={v=>{SubWorkflowStatusStore.appendFormFields({requestname:v})}}
                  />
                  <WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@uvaaor`}
                      comsWeaTableStore={tableStore}
                      hasOrder={true}
                      needScroll={true}
                      register_table={SubWorkflowStatusStore.reLoad}
                  />
              </WeaTop>
          </WeaRightMenu>
      </div>
    )
  }



  //搜索框底部按钮
  getTabButtonsAd() {
    const { SubWorkflowStatusStore } = this.props;
    return [
        (<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@4f0x75@search`} type="primary" onClick={()=>{SubWorkflowStatusStore.getSessionkey();SubWorkflowStatusStore.setShowSearchAd(false);}}>{getLabel(197,'搜索')}</Button>),
        (<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@o1ycid@reset`} type="ghost" onClick={()=>{SubWorkflowStatusStore.clearFormFields();}}>{getLabel(2022,'重置')}</Button>),
        (<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@hzo6yt@cancel`} type="ghost" onClick={()=>{SubWorkflowStatusStore.setShowSearchAd();}}>{getLabel(31129,'取消')}</Button>)
    ];
  }


    //右键菜单方法
   getRightMenu(){
      const { SubWorkflowStatusStore ,location} = this.props;
      const { tableStore, form} = SubWorkflowStatusStore;
      const selectedRowKeys = tableStore.selectedRowKeys;
      const selectedLen = tableStore.selectedRowKeys.length;
      const formParams = form.getFormParams();
      let btns = [];

      btns.push({
        key: "search",
        icon: <i className='icon-workflow-Right-menu--search'/>,
        content:getLabel(197,'搜索'),
        onClick: key =>{SubWorkflowStatusStore.getSessionkey();}
      });

      btns.push({
          key:"colSet",
          icon: <i className='icon-coms-Custom'/>,
          content:getLabel(32535,'显示列定制'),
          onClick: key =>{
            tableStore.setColSetVisible(true);
            tableStore.tableColSet(true);
          }
      });
     return btns;
  }



}

export default WeaTools.tryCatch(React,
    props => <WeaErrorPage ecId={`${this && this.props && this.props.ecId || ''}_WeaErrorPage@3j89bp`} msg={ props.error ? props.error : getLabel(383324,'对不起，该页面异常，请联系管理员！')} />,
    {error: ""}
    )(SubWorkflowStatus);
